﻿using System.Configuration;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using Projecturo.Connectivity;

namespace Projecturo.ProjecturoClient.Connection
{
    public static class Connector
    {
        private static IUnityContainer unityContainer;
        private static IConnectivity connectivity;

        public static IUnityContainer UnityContainer
        {
            get
            {
                if (unityContainer == null)
                {
                    unityContainer = new UnityContainer();
                    UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
                    section.Containers["Connectivity"].Configure(unityContainer);

                }
                return unityContainer;
            }
        }

        public static IConnectivity Connectivity
        {
            get
            {
                if (connectivity == null)
                {
                    connectivity = UnityContainer.Resolve<IConnectivity>();
                    connectivity = UnityContainer.BuildUp<IConnectivity>(connectivity);
                }
                return connectivity;
            }
        }
    }
}
